home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)plot_ps.c V1.20 3/13/95";
- #endif
- /*
- | file name - plot_ps.c
- |=======================================================================
- |
- | This is an example program that demonstrates printing to a
- | printer from within a DV-Tools program. Printing may be performed
- | by any windows supported printer.
- | There are three print commands:
- |
- | TscPrintSet - this takes a variable argument list that allows
- | different printer settings. See the documentation
- | for a list of possible settings. Returns an ADDRESS
- | which is passed into TscPrintStart.
- | TscPrintStart - starts the print process. Accepts a SCREEN as the
- | first argument and an ADDRESS or NULL as the second
- | argument.
- | TscPrintEnd - notifies the program that printing is over. Accepts
- | a SCREEN argument.
- |
- | The programmer starts the the print process with TscPrintStart and
- | then proceeds to draw to the printer. Between the start and end functions
- | the application DC is assign to the printer. Any GDI routines used
- | will be printed to the designated printer.
- |
- |=======================================================================
- */
-
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VPfundecl.h" /* VP routines (put info for dgp & vdp) */
- #include "VGfundecl.h" /* VG routines (get info from dgp & vdp) */
- #include "VUfundecl.h" /* VU routines (Utility) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "plot.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- /* Define & initialize view filename */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define global variables */
- int slot_count, plot_file_count = 0;
- int draw_times = 0;
- float time_start, incr;
-
- /* Functions defined in plot_ps.c */
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
-
- {
- /*
- * program arguments
- * argv[1] - display device name (default is to use DVDEVICE)
- * argv[2] - view name (default is plot.v)
- */
-
- /* Define & initialize device name */
- char *device_name = DVDEVICE; /* default device name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Other variables */
- OBJECT drawing, /* graphical representation of screen */
- graph_obj; /* graph object */
- DATAGROUP dgp; /* data group pointer structure */
- char *obj_name; /* name of objects selected */
- int Quit = NO; /* flag to quit program */
- int argc = 0;
- char **argv;
-
-
- make_argv(&argc,&argv,GetCommandLine());
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase (screen);
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file, either a
- * user supplied view or default view file plot.v
- */
- if (argc == 3)
- view_name = argv[2];
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TdrGetNamedObject: Gets a named object from a
- * drawing.
- *
- * Obtain the graph object from the view's drawing.
- */
- drawing = TviGetDrawing (view);
- graph_obj = TdrGetNamedObject (drawing, "graph");
-
- /*
- * VOdgGetDgp: Returns pointer to the data group structure
- * VGdgslots: Gets the number of data group slots
- * VGdgtime_start_incr: Gets the time axis start and increment
- *
- * Obtain the data group pointer which is used to retrieve
- * information about the graph such as slot count, time axis
- * start and time axis increment value.
- */
- dgp = VOdgGetDgp (graph_obj);
- slot_count = VGdgslots (dgp);
- VGdgtime_start_incr (dgp, &time_start, &incr);
-
- /*
- * TdpCreate: Create a DV-Tools window, a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * TviOpenData: Open all data source lists for this view and views
- * referenced by enabled subdrawings contained in view
- * TviReadData: Reads data from the data sources of a view
- */
- TviOpenData (view);
- TviReadData (view);
-
- /*
- * TdpDraw: Draw the contents of a drawport
- */
- TdpDraw (drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the window event queue. If the user selects an object
- * named quit then exit the program. If the user selects the
- * plot button then print out the current screen display to
- * the Postscript printer. The drawport's dynamic objects
- * are updated with the current iteration of data each time
- * through the loop.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_NO_WAIT.
- * Using this mode, VOloWinEventPoll
- * does not wait until a masked event
- * is generated.
- */
- location = VOloWinEventPoll (V_NO_WAIT);
- if (location)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- break;
-
- case V_BUTTONPRESS:
- /*
- * Check button selected.
- * VOloButton: Returns the button that was pressed
- * TloGetSelectedObjectName: Get the name of the selected object
- *
- * The left mouse button acts as the selection button. If
- * the object selected by the user has a name then compare
- * this name to the exit string "quit_button". If they
- * match then exit the program. Otherwise check to see if
- * name matches the plot button string, "plot_button". If
- * so, call the function to plot the screen.
- */
- switch (VOloButton (location))
- {
- case 1:
- obj_name = TloGetSelectedObjectName (location);
- if (obj_name)
- {
- if( strcmp( obj_name, "quit_button" ) == 0 )
- Quit = YES;
- else
- if( strcmp( obj_name, "plot_button" ) == 0 )
- {
- ADDRESS print_info; /* Object to be passed into TscPrintStart */
-
- /* Set the printer attributes */
- print_info = TscPrintSet(VP_PRINT_SCALE, 50,
- VP_PRINT_ITER_COUNT, 10,
- V_END_OF_LIST);
-
- /* Start the print process, any display calls between TscPrintStart
- and TscPrintEnd will be sent to the printer */
- TscPrintStart(screen, print_info);
-
- /* Call to redraw the screen, only now it goes to the printer */
- TscRedraw(screen, NULL);
-
- /* End the print process, all display calls after this will
- affect the display monitor */
- TscPrintEnd(screen);
- }
- }
-
- default:
- break;
- }
- break;
-
- default:
- break;
- }
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
-
- /*
- * Update the number of draw times counter
- */
- draw_times += 1;
-
- /*
- * TviReadData: Read data from the data sources of the view.
- * TdpDrawNext: Update all dynamic objects within a drawport's view
- */
- TviReadData (view);
- TdpDrawNext (drawport);
- }
-
- /*--------------------
- * Termination
- *
- * TdpDestroy: Destroy the drawport,
- * TviCloseData: Close the data sources of the view
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscClose: Closes the screen object
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TdpDestroy (drawport);
- TviCloseData (view);
- TviDestroy (view);
- TscClose (screen);
- TTerminate ();
- return EXIT_OK;
- }
-
-